//出厂测试

#include "App_Main.h"
uint8_t FactoryEnable;


uint8_t Factory_ProbeCheck(void)
{
    uint32_t temp;

    if(key_param.once2 == 1)
    {
        temp = Tube_Encoder_P;
        temp <<= 8;
        temp |= Tube_Encoder_S;
        temp <<= 8;
        temp |= 1;
        NT_CharsSettings(temp);
        return 1;
    }
    return 0;
}
void Factory_main(void)
{
    uint32_t FanCtrl_Fan = 0;
    uint32_t FanCtrl_Heater = 1;
    uint32_t FanCtrl_Feed = 1;
    uint8_t i;
    uint32_t temp;
    uint32_t temp_rtd;

    KeyDetection();
    if(key_param.once1 == 1)
    {
        for (i = 0; i < 10; i++) keyboard_delay15ms();
        if(key_param.once1 == 1)
        {
            FactoryEnable = 1;
            IgniterClose;
            HeaterFanClose;
            ExhaustFanClose;
            FanCtrl_Fan = 0;
            FanCtrl_Heater = 0;
            FanCtrl_Feed = 0;
            key_mset_state = 0;
            Keyboard1_Show_Count = 0;
        }
    }
    NT_Init();
    while (FactoryEnable)
    {
        WDT_Clear();
		TempADC_Main();
        KeyDetection();
        SwitchKey();
        if(Switch_State == Temp_Shutoff)
        {
            temp = Tube_Encoder_None;
            temp <<= 8;
            temp |= Tube_Encoder_None;
            temp <<= 8;
            temp |= Tube_Encoder_None;
            if(RTD[0].status == Pt_Normal)
            {
                temp_rtd = RTD[0].value;
                if(UI_System.Grill_Unit == Unit_C)
                {
                    temp_rtd = F_Convert_C(temp_rtd);
                }
                temp = (temp_rtd / 100) % 10;
                temp <<= 8;
                temp |= (temp_rtd / 10) % 10;
                temp <<= 8;
                temp |= temp_rtd % 10;
                
            }
            IgniterClose;
            HeaterFanClose;
            ExhaustFanClose;
            NT_CharsSettings(temp);
        }
        else
        {
            if(Switch_State == Temp_Set_Smoke)
            {
                if(RTD[1].status == Pt_Normal)
                {
                    temp_rtd = RTD[1].value;
                    if(UI_System.Grill_Unit == Unit_C)
                    {
                        temp_rtd = F_Convert_C(temp_rtd);
                    }
                    temp = (temp_rtd / 100) % 10;
                    temp <<= 8;
                    temp |= (temp_rtd / 10) % 10;
                    temp <<= 8;
                    temp |= temp_rtd % 10;
                }
                else 
                {
                    temp = Tube_Encoder_O;
                    temp <<= 8;
                    temp |= Tube_Encoder_O;
                    temp <<= 8;
                    temp |= Tube_Encoder_O;
                }
                ExhaustFanOpen;
                if(Factory_ProbeCheck() == 0)
                {
                    NT_CharsSettings(temp);
                }
                continue;
            }
            else if(Switch_State == Temp_Set_200)
            {
                if(RTD[2].status == Pt_Normal)
                {
                    temp_rtd = RTD[2].value;
                    if(UI_System.Grill_Unit == Unit_C)
                    {
                        temp_rtd = F_Convert_C(temp_rtd);
                    }
                    temp = (temp_rtd / 100) % 10;
                    temp <<= 8;
                    temp |= (temp_rtd / 10) % 10;
                    temp <<= 8;
                    temp |= temp_rtd % 10;
                }
                else 
                {
                    temp = 1;
                    temp <<= 8;
                    temp |= 1;
                    temp <<= 8;
                    temp |= 1;
                }
                IgniterOpen;
                if(Factory_ProbeCheck() == 0)
                {
                    NT_CharsSettings(temp);
                }
                continue;
            }
            else if(Switch_State == Temp_Set_225)
            {
                Factory_Show_Num = 222;
                HeaterFanOpen;
            }
            else if(Switch_State == Temp_Set_250)
            {
                Factory_Show_Num = 333;
                ExhaustFanClose;
            }
            else if(Switch_State == Temp_Set_300)
            {
                Factory_Show_Num = 444;
                IgniterClose;
            }
            else if(Switch_State == Temp_Set_350)
            {
                Factory_Show_Num = 555;
                HeaterFanClose;
            }
            else if(Switch_State == Temp_Set_400) Factory_Show_Num = 666;
            else if(Switch_State == Temp_Set_450) Factory_Show_Num = 777;
            else if(Switch_State == Temp_Set_475) Factory_Show_Num = 888;
            else if(Switch_State == Temp_Set_500) Factory_Show_Num = 999;

            if(Factory_ProbeCheck() == 0)
            {
                NT_NumsSettings(Factory_Show_Num);
            }
        }
    }
}
